﻿using Glue;
using Xunit;

namespace GlueTests.MappingTests
{
    public class When_adding_a_relation_with_readonly_property
    {
        private readonly Mapping<DomainPerson, GuiPerson> mapping;

        public class DomainPerson { public int Id { get; private set; } }
        public class GuiPerson { public int Id { get; set; } }

        public When_adding_a_relation_with_readonly_property()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();
        }

        [Fact]
        public void Should_throw_exception_when_trying_to_relate_both_ways()
        {
            Assert.Throws<GlueException>(() => 
                                             mapping.Relate(left => left.Id, right => right.Id)
                );
        }

        [Fact]
        public void Should_throw_exception_when_trying_to_relate_towards_ReadOnly()
        {
            Assert.Throws<GlueException>(() =>
                                             mapping.RelateTowardsLeft(left => left.Id, right => right.Id)
                );
        }

        [Fact]
        public void Should_succeed_when_trying_to_relate_away_from_ReadOnly()
        {
            mapping.RelateTowardsRight(left => left.Id, right => right.Id);
        }
    }
}